package com.bestv.xml.processor;

import com.bestv.database.dao.DaoFactory;
import com.bestv.database.vo.IncrProgram;
import com.bestv.xml.parser.ProgramParser;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Henry on 14-7-10.
 */
public class ProgramProcessor extends Processor {
    public ProgramProcessor() {
        super();
        xmlFilePattern = "Program_.*\\.xml";
    }

    public void process() {
        ProgramParser parser = new ProgramParser();
        List<IncrProgram> programs = new ArrayList<IncrProgram>();
        for (File file : getFiles()) {
            IncrProgram program = parser.parse(file);
            if (program != null) {
                programs.add(program);
                moveToDoneFolder(file);
            } else {
                moveToErrorFolder(file);
            }
        }
        DaoFactory.getIncrProgramDao().truncate();
        DaoFactory.getIncrProgramDao().saveBatch(programs);
    }
}
